package com.ujson.uaa.repository.impl;

import com.ujson.uaa.persistence.UserDao;
import com.ujson.uaa.repository.UserRepository;
import com.ujson.uaa.types.User;
import com.ujson.uaa.types.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class UserRepositoryImpl implements UserRepository {

    @Autowired
    private UserDao userDao;
    private UserMapper userMapper = UserMapper.INSTANCE;

    @Override
    public User findByUserName(String username) {
        return userMapper.convert(userDao.findByUserName(username));
    }

    @Override
    public User register(User user) {
        return userMapper.convert(userDao.save(userMapper.convert(user)));
    }

}
